import 'package:flutter/cupertino.dart';
import 'package:my_app_01/pages/app.dart';
import 'package:my_app_01/pages/auth/login.dart';
import 'package:my_app_01/pages/common/404.dart';
import 'package:my_app_01/pages/me/index.dart';
import 'package:my_app_01/pages/me/person_info.dart';
import 'package:my_app_01/pages/menu/index.dart';

class RouterTable {
  static String splashPath = '/splash';
  static String loginPath = '/auth/login';
  static String homePath = '/home';
  static String notFoundPath = '/404';
  static String menuPath = '/menu';
  static String mePath = '/me';
  static String personInfo = '/me/person_info';

  static Map<String, WidgetBuilder> routeTables = {
    //404页面
    notFoundPath: (context) => const NotFoundPage(),
    // 启动页
    // splashPath: (context) => Splash(),
    // 登录
    loginPath: (context) => LoginPage(),
    // 首页
    homePath: (context) => AppPage(),
    // 菜单页
    menuPath: (context) => MenuPage(),
    // 我的
    mePath: (context) => MePage(),
    // 个人信息
    personInfo: (context) => const PersonInfoPage(),

  };

  ///路由拦截
  static Route onGenerateRoute<T extends Object>(RouteSettings settings) {
    return CupertinoPageRoute<T>(
      settings: settings,
      builder: (context) {
        String? name = settings.name;
        if (routeTables[name] == null) {
          name = notFoundPath;
        }

        Widget widget = routeTables[name]!(context);

        return widget;
      },
    );
  }
}
